package com.csi.juegoweb.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.csi.juegoweb.dao.DonacionDAO;
import com.csi.juegoweb.domain.Donacion;

@Repository("donacionDao")
public class DonacionDAOJdbc implements DonacionDAO{
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<Donacion> getDonaciones() {
		// TODO Auto-generated method stub
		return jdbcTemplate.query("select Co_donacion," +
				"Co_jugador," +
				"Co_jugdes," +
				"Fl_confirn," +
				"Fc_confirn," +
				"Nu_monto from Donacion", 
				new BeanPropertyRowMapper<Donacion>(Donacion.class));
	}

	@Override
	public void eliminar(Integer codonacion) {
		
		jdbcTemplate.update("delete from donacion" +
				" where co_donacion = ?",codonacion);
		
	}

	@Override
	public void crear(Donacion dancion) {
		// TODO Auto-generated method stub
		jdbcTemplate.update("insert into donacion (" +
				"Co_jugador," +
				"Co_jugdes," +
				"Fl_confirn," +
				"Fc_confirn," +
				"Nu_monto) values (?, ?, ?, ?, ?)",
				dancion.getCojugador(),
				dancion.getCoJugdes(),
				dancion.getFcConfirn(),
				dancion.getFcConfirn(),
				dancion.getNuMonto());
	}

}
